<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006-2016 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 流年 <liu21st@gmail.com>
// +----------------------------------------------------------------------

// 应用公共文件
function p($msg = []){
    echo "<pre>";
    print_r($msg);
    echo "</pre>";
    die;
}

function fileExt($filename, $type = 0)
{
    switch($type){
        case 0:
            $ext = substr(strrchr($filename,'.'),1);
            //subrchr:查找字符在另一字符串最后一次出现的位置，并返回从该位置到结尾的字符
            break;
        case 1:
            $ext = substr($filename, strrpos($filename, '.')+1);
            //strpos:查找字符最后一次出现的位置，返回位置
            break;
        case 2:
            $arr = explode('.', $filename);
            $ext = $arr[count($arr)-1];
            break;
        case 3:
            $arr = explode('.', $filename);
            $ext = end($arr);
            //end函数 返回数组的最后一个元素
            break;
        case 4:
            $ext = strrev(explode('.', strrev($filename))[0]);
            //strrev:翻转字符串
            break;
        case 5:
            $ext = pathinfo($filename)['extension'];
            //pathinfo:以数组形式返回文件路径信息，[dirname],[basename],[extension]
            break;
        case 6:
            $ext = pathinfo($filename,PATHINFO_EXTENSION);
            //pathinfo 可以指定第二个参数，返回指定的信息：PATHINFO_DIRNAME,PATHINFO_BASENAME,PATHINFO_EXTENSION
            break;
    }
    return $ext;
}

function dirFile($path = '')
{

    if(!is_dir($path)) return false;

    $handle = opendir($path);

    if($handle){
        while(($fl = readdir($handle)) !== false){
            $temp = $path.DIRECTORY_SEPARATOR.$fl;
            //如果不加  $fl!='.' && $fl != '..'  则会造成把$dir的父级目录也读取出来
            if(is_dir($temp) && $fl!='.' && $fl != '..'){
                echo 'dir----'.$temp."\r\n";
                read_all($temp);
            }else{
                if($fl!='.' && $fl != '..'){
                    echo "filepath---$temp \r\n";
                }
            }
        }
    }
}

function coding($str = '')
{
    $fileType = mb_detect_encoding($str,array('UTF-8','GBK','LATIN1','BIG5'));
    if($fileType != 'UTF-8') {
        $str = mb_convert_encoding($str,'utf-8',$fileType);
    }
    return $str;
}

function toPdf($content = '')
{

}